package main

import (
	"flag"
	"fmt"
	"os"
	"runtime/trace"
	"time"

	"gitee.com/dn-jinmin/tdg/build"
)

/**
 * @Author DNjinmin
 */
var (
	configFile = flag.String("config", "./etc/table.json", "TDG config file")
)

func main() {

	flag.Parse()
	arg := flag.Args()

	if len(arg) > 0 && arg[0] == "tag" {
		build.NewConsole().Tags()
		return
	}

	fmt.Println("数据添加完成 : 开始 ：", time.Now())

	cfg, err := build.NewConfigWithFile(*configFile)
	if err != nil {
		fmt.Println("【config】new config err := ", err, "\n【问题】1.是否指定--config、2.检查配置参数")
		return
	}

	b, err := build.NewBuild(cfg)
	if err != nil && !cfg.SkipErr {
		fmt.Println("【build】new build err := ", err)
		return
	}

	b.Run()

	fmt.Println("数据添加完成 : 结束 : ", time.Now())
}

func setTrace(name string, fn func()) {
	f, _ := os.Create(name)
	defer f.Close()
	// 启动trace 对程序的执行进行分析捕捉
	err := trace.Start(f)
	if err != nil {
		panic(err)
	}
	defer trace.Stop()

	fn()
}
